#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import requests
import json
import time

from queue import Queue #LILO队列
from selenium import webdriver;
from selenium.common.exceptions import TimeoutException
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from  xueqiu.spider_zuhe import update

def time_parse(timeStamp):
    localTime = time.localtime(timeStamp)
    strTime = time.strftime("%Y-%m-%d %H:%M:%S", localTime)
    print(strTime)


def test_nlu():
    info = "明天早上八点打开网络机顶盒"
    url = "http://139.219.111.245/hakuNLP?user_input={info}".format(info=info)
    res = requests.get(url)
    if res.status_code == 200:
        result = res.text
        print(result)
        if result != None and "{}" not in result:
            res = json.loads(result)
            par = res.get("result").get("semantics").get("request").get("param")
            if "时间" in par:
                time_parse(par.get("时间"))




    else:
        print("error")




# def update():
#     print("update cookies")
#     chromeOptions = webdriver.ChromeOptions()
#     # 设置代理
#     try:
#         get_ips()
#         get_ips()
#         ips=proxy = 'http://'+get_ips()
#         print("get cookies ip",ips)
#         chromeOptions.add_argument("--proxy-server=" +ips )
#         # 一定要注意，=两边不能有空格，不能是这样--proxy-server = http://202.20.16.82:10152
#         browser = webdriver.Chrome(chrome_options=chromeOptions)
#         # browser=webdriver.Chrome()
#         # browser.set_window_size(1400,900)
#         wait = WebDriverWait(browser, 10)
#         global cookies
#         browser.get("http://www.httpbin.org/ip")
#         # cube - content
#         # user_name = wait.until(
#         #     EC.presence_of_element_located((By.CSS_SELECTOR, "cube-content"))
#         # )
#         results = browser.get_cookies()
#         print(browser.page_source)
#         for res in results:
#             cookies[res.get("name")] = res.get("value")
#         browser.quit()
#     except Exception as  e:
#         print(e)


update()






